package pa2.node;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Map;

import pa2.system.Peer;
import pa2.system.PeerImpl;
import pa2.util.Callback;
import pa2.util.EqualityCompare;
import pa2.util.Event;
import pa2.util.LogCallback;
import pa2.util.PeerNameEvent;

public class StatisticNode <K extends EqualityCompare<K>, V, M extends Map<K,V>> 
	extends NodeDecorator<K,V,M> implements Node<K,V,M>, Serializable{

	private Event event;

	protected StatisticNode(Node<K, V, M> decoratedNode, Event event) throws RemoteException {
		super(decoratedNode);
		this.event = event;
	}

	@Override
	public void put(K key, V value, Callback<K, V> callback)
			throws RemoteException {
		//if the callback is an instance of MessageLogCallback, log the incoming message
		if(callback instanceof LogCallback){
			((LogCallback<K,V>) callback).logEvent(this.event);
		}
		super.put(key, value, callback);
	}

	@Override
	public void get(K key, Callback<K, V> callback) throws RemoteException {
		//if the callback is an instance of MessageLogCallback, log the incoming message
		if(callback instanceof LogCallback){
			((LogCallback<K,V>) callback).logEvent(this.event);
		}
		super.get(key, callback);
	}

	@Override
	public void remove(K key, Callback<K, V> callback) throws RemoteException {
		//if the callback is an instance of MessageLogCallback, log the incoming message
		if(callback instanceof LogCallback){
			((LogCallback<K,V>) callback).logEvent(this.event);
		}
		super.remove(key, callback);
	}
	
	

}
